//package me.firstapp.weixin.controller.kami;
//
//import java.util.ArrayList;
//import java.util.List;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.ModelMap;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.mvc.support.RedirectAttributesModelMap;
//
//import me.firstapp.common.exception.ServiceException;
//import me.firstapp.common.exception.StatusHouse;
//import me.firstapp.module.weixin.kami.KaMiCategory;
//import me.firstapp.module.weixin.kami.KaMiProduct;
//import me.firstapp.module.weixin.member.Member;
//import me.firstapp.module.weixin.order.KaMiOrder;
//import me.firstapp.service.weixin.kami.KaMiCategoryService;
//import me.firstapp.service.weixin.kami.KaMiOrderService;
//import me.firstapp.service.weixin.kami.KaMiProductService;
//import me.firstapp.service.weixin.member.MemberService;
//import me.firstapp.weixin.controller.base.BaseController;
//
//@Controller
//public class KaMiController extends BaseController {
//
//	@Autowired
//	private KaMiCategoryService kaMiCategoryService;
//
//	@Autowired
//	private KaMiProductService kaMiProductService;
//
//	@Autowired
//	private MemberService memberService;
//
//	@Autowired
//	private KaMiOrderService kaMiOrderService;
//
//	@RequestMapping("/page/kamiList.htm")
//	public ModelAndView kamiList(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
//		String openId = getCurrentLoginOpenId(request, response);
//		Member member = memberService.findMemberByOpenId(openId);
//		if (null == member) {
//			throw new ServiceException(StatusHouse.STATUS_PAGE_ERROR_NOT_CONCERN_WEIXIN);
//		}
//		modelMap.put("vipLevel", member.getVipLevel());
//		List<CategoryKaMiPair> categoryKaMiPairs = new ArrayList<>();
//		List<KaMiCategory> kaMiCategories = kaMiCategoryService.findKaMiCategorys();
//		for (KaMiCategory kaMiCategory : kaMiCategories) {
//			List<KaMiProduct> products = kaMiProductService.findKaMiProductListByCategory(kaMiCategory.getId(),
//					KaMiProduct.CHANNEL_EXCHANGE);
//			CategoryKaMiPair categoryKaMiPair = new CategoryKaMiPair();
//			categoryKaMiPair.setKaMiCategory(kaMiCategory);
//			categoryKaMiPair.setProducts(products);
//			categoryKaMiPairs.add(categoryKaMiPair);
//		}
//		modelMap.put("categoryKaMiPairs", categoryKaMiPairs);
//		return new ModelAndView("kami/kamiList", modelMap);
//	}
//
//	@RequestMapping("/page/confirmKmOrderPage.htm")
//	public ModelAndView confirmKmOrderPage(Long kaMiProductId, String remark, HttpServletRequest request,
//			HttpServletResponse response, RedirectAttributesModelMap modelMap) {
//		String openId = getCurrentLoginOpenId(request, response);
//		KaMiOrder kaMiOrder = kaMiOrderService.executeCreateKaMiOrder(openId, kaMiProductId, remark);
//		modelMap.addFlashAttribute("kaMiOrder", kaMiOrder);
//		request.getSession().setAttribute("kaMiOrder", kaMiOrder);
//		return new ModelAndView("redirect:/page/confirmKmOrder.htm", modelMap);
//	}
//
//	@RequestMapping("/page/confirmKmOrder.htm")
//	public ModelAndView confirmKmOrder(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) {
//		getCurrentLoginOpenId(request, response);
//		if (!modelMap.containsAttribute("kaMiOrder")) {
//			modelMap.put("kaMiOrder", request.getSession().getAttribute("kaMiOrder"));
//		}
//		KaMiOrder kaMiOrder = (KaMiOrder) modelMap.get("kaMiOrder");
//		if (null != kaMiOrder) {
//			KaMiProduct kaMiProduct = kaMiProductService.findById(kaMiOrder.getKaMiProductId());
//			modelMap.put("remarkTip", kaMiProduct.getOrderRemarkTip());
//			modelMap.put("detail", kaMiProduct.getRemark());
//		}
//		return new ModelAndView("kami/confirmKmOrder", modelMap);
//	}
//
//	@RequestMapping("/page/pointExchangePage.htm")
//	public ModelAndView showPointExchangePage(HttpServletRequest request, HttpServletResponse response,
//			ModelMap modelMap) {
//		String openId = getCurrentLoginOpenId(request, response);
//		Member member = memberService.findMemberByOpenId(openId);
//		if (null == member) {
//			throw new ServiceException(StatusHouse.STATUS_PAGE_ERROR_NOT_CONCERN_WEIXIN);
//		}
//		modelMap.put("vipLevel", member.getVipLevel());
//
//		List<KaMiProduct> kaMiProducts = kaMiProductService.findExchangeKaMiProductList();
//		modelMap.put("kaMiProducts", kaMiProducts);
//		return new ModelAndView("kami/pointExchange", modelMap);
//	}
//}
